package com.mcptt.notify.presence;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;

public class Tuple
{
    public static final String Name = "tuple";
    private static final String Name_Id = "id";

    private String id = null;
    private Status status = null;
    
    

    public void parse(Element elem) throws JDOMException
    {
	if(elem == null)
	{
	    return;
	}
	id = elem.getAttributeValue(Name_Id);

	List<Element> list = elem.getChildren();//锟斤拷酶锟斤拷诘锟斤拷锟接节碉拷  
	for(Element subElem:list) 
	{
	    String name = subElem.getName();
	    Log.debug(this.getClass(), "name = " + name);
	    if(name == null
		    || name.length() <= 0)
	    {
		return;
	    }
	    if(name.equals(Status.Name))
	    {
		status = new Status();
		status.parse(subElem);
	    }
	}  
    }

    public String getRoot()
    {
	return id;
    }
    
    public Status getStatus()
    {
        return status;
    }

    public String toString()
    {
	StringBuffer strBuf = new StringBuffer("\r\n");
	strBuf.append("<").append(Name).append(" ").append(Name_Id).append("=\"").append(id).append("\" >");
	strBuf.append(status);
	strBuf.append("</").append(Name).append(">");

	return strBuf.toString();
    }
}
